<template>
    <div id="adminsCheck">
        <h1>理赔列表</h1>
        <el-table :data="filterApplyIng" style="width: 100%">
            <el-table-column type="expand">
                <template slot-scope="props">
                    <el-form
                        label-position="left"
                        inline
                        class="demo-table-expand"
                    >
                        <el-form-item label="ID">
                            <span>{{ props.row._id }}</span>
                        </el-form-item>
                        <el-form-item label="所属订单">
                            <span>{{ props.row.ordersId._id }}</span>
                        </el-form-item>
                        <el-form-item label="所属用户">
                            <span>{{ props.row.ordersId.usersId.name }}</span>
                        </el-form-item>
                        <el-form-item label="投保经理">
                            <span>{{
                                props.row.ordersId.personalId.names
                            }}</span>
                        </el-form-item>
                        <el-form-item label="申请时间">
                            <span>{{ props.row.applyTime }}</span>
                        </el-form-item>
                        <el-form-item label="处理时间">
                            <span>{{ props.row.handleTime }}</span>
                        </el-form-item>
                        <el-form-item label="理赔状态">
                            <span>{{ props.row.state }}</span>
                        </el-form-item>
                        <el-form-item label="事故时间">
                            <span>{{ props.row.accidentTime }}</span>
                        </el-form-item>
                        <el-form-item label="相关图片">
                            <!-- <span>{{ props.row.images }}</span> -->
                            <template v-for="item in props.row.images">
                                <img
                                    :src="
                                        'http://localhost:3000/images/' + item
                                    "
                                    alt=""
                                    :key="item"
                                />
                            </template>
                        </el-form-item>
                    </el-form>
                </template>
            </el-table-column>
            <el-table-column label="ID" prop="_id"> </el-table-column>
            <el-table-column label="申请时间" prop="applyTime">
            </el-table-column>
            <el-table-column label="申请状态">
                <template slot-scope="scope">
                    <span v-if="scope.row.state === 1" style="color: orange">{{
                        claimsState(scope.row.state)
                    }}</span>
                    <span v-if="scope.row.state === 2" style="color: green">{{
                        claimsState(scope.row.state)
                    }}</span>
                    <span v-if="scope.row.state === 3" style="color: red">{{
                        claimsState(scope.row.state)
                    }}</span>
                </template>
            </el-table-column>
            <el-table-column label="所属订单">
                <template slot-scope="scope">
                    <span>{{ scope.row.ordersId._id }}</span>
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button
                        size="mini"
                        @click="disagreeReapply(scope.row._id)"
                        type="danger"
                        >拒绝</el-button
                    >
                    <el-button size="mini" @click="agreeReapply(scope.row._id)"
                        >同意</el-button
                    >
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
//引入状态机辅助函数
import { createNamespacedHelpers } from "vuex";
// 拿到 理赔分仓 进行操作
const { mapState, mapActions, mapMutations } = createNamespacedHelpers(
    "claims"
);
export default {
    computed: {
        ...mapState(["claimsListData"]),
        //筛选出申请中的理赔
        filterApplyIng() {
            return this.claimsListData.filter((item) => item.state === 1);
        },
    },
    mounted() {
        this.setPageSize(10);
        this.getClaims();
    },
    methods: {
        ...mapMutations(["setUpdateClaimsData", "setPageSize"]),
        ...mapActions(["getClaims", "agreeReapply", "disagreeReapply"]),
        //处理理赔订单申请状态
        claimsState(data) {
            switch (data) {
                case 1:
                    return "申请中";
                case 2:
                    return "申请成功";
                case 3:
                    return "申请失败";
            }
        },
    },
};
</script>

<style lang="scss" scope>
#adminsCheck {
    h1 {
        line-height: 50px;
        margin-left: 30px;
    }
    .el-button--mini {
        font-size: 14px;
    }
    .el-table .cell {
        box-sizing: border-box;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: normal;
        word-break: break-all;
        line-height: 50px;
        padding-left: 10px;
        padding-right: 10px;
    }
    .el-form {
        width: 1069px;
        height: 385px;
        margin: 0px auto;
        border: 1px solid gainsboro;
        padding: 50px 50px;
    }
    .el-form-item__label {
        text-align: left;
        vertical-align: middle;
        float: left;
        font-size: 14px;
        color: #606266;
        line-height: 40px;
        padding: 0 12px 0 0;
        box-sizing: border-box;
        margin-left: 30px;
        width: 100px;
    }
    .demo-table-expand {
        font-size: 0;
    }
    .demo-table-expand label {
        width: 90px;
        color: #99a9bf;
    }
    .demo-table-expand .el-form-item {
        margin-right: 0;
        margin-bottom: 0;
        width: 50%;
    }
    //弹窗
    .el-dialog {
        position: relative;
        margin: 0 auto;
        width: 1000px;
        background: #ffffff;
        border-radius: 2px;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
        box-sizing: border-box;
        width: 50%;
        .el-dialog__body {
            padding: 30px 20px;
            color: #606266;
            font-size: 14px;
            word-break: break-all;
            .el-input__inner {
                margin-bottom: 20px;
                padding-left: 10px;
            }
        }
    }
    img {
        margin-right: 5px;
        width: 100px;
    }
}
</style>